package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Client;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IClientService;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("client")
public class ClientController {

    @Autowired
    IClientService clientService;

    @RequestMapping("/list")
    @RequiredPermission({"客户列表","client:list"})
    public String list(QueryObject qo, Model model){
        model.addAttribute("result",clientService.query(qo));
        return "client/list";
    }

    @RequestMapping("saveOrUpdate")
    @RequiredPermission({"客户新增或编辑","client:saveOrUpdate"})
    public String saveOrUpdate(Client client){
        clientService.saveOrUpdate(client);
        return "redirect:/client/list.do";
    }

    @RequestMapping("input")

    public String input(Model model,Long id){
        if(id != null){
            Client d = clientService.get(id);
            model.addAttribute("entity",d);
        }
        return "client/input";
    }

    @RequestMapping("/delete")
    @RequiredPermission({"客户删除","client:delete"})
    public String delete(Long id){
        clientService.delete(id);
        return "redirect:/client/list.do";
    }
}
